package com.project.mvprxsample.net;

import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import com.project.mvprxsample.bean.BaseResult;

import rx.Observer;

/**
 * 请求返回统一处理
 */
public abstract class MyObserver implements Observer<BaseResult> {

    private Context mContext;

    public MyObserver(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public void onCompleted() {

    }

    @Override
    public void onError(Throwable e) {
        e.printStackTrace();
        Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onNext(BaseResult baseResult) {
        try {
            int statusCode = baseResult.getStatusCode();
            if (HttpStateCode.HTTP_SUEECSS_STATE == statusCode) {

            } else if (HttpStateCode.LOGIN_OUT == statusCode) {

            } else {
                Toast.makeText(mContext, baseResult.getMessage(), Toast.LENGTH_SHORT).show();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
